//
//  AY_BookBDCollectCell.m
//  AiYue
//
//  Created by 姜栋梁 on 2023/12/16.
//

#import "AY_BookBDCollectCell.h"

@interface AY_BookBDCollectCell ()

/** 书 */
@property (strong,nonatomic) UIImageView *bookImage;

/** 书名 */
@property (strong,nonatomic) UILabel *bookName;

@property (strong,nonatomic) UILabel *indexLabel;
@property (strong,nonatomic) UILabel *tipLabel;
@property (strong,nonatomic) UILabel *authorLabel;

@end

@implementation AY_BookBDCollectCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllSubviewsWithUI];
    }
    return self;
}

- (void)addAllSubviewsWithUI {
    self.bookImage = [AYTool createImageViewWithFrame:CGRectZero andImage:nil andBg:nil andRadius:YNUM(4) andAddSubView:self.contentView];
    [self.bookImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(YNUM(15));
        make.top.equalTo(self.contentView).offset(YNUM(12));
        make.width.mas_equalTo(YNUM(52));
        make.height.mas_equalTo(YNUM(70));
    }];
    
    self.tipLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:[UIColor whiteColor] andBgColor:nil andFont:YFont(8) andLines:1 andRadius:0 andAddSubView:self.bookImage];
    self.tipLabel.layer.masksToBounds = NO;
    self.tipLabel.textAlignment = NSTextAlignmentCenter;
    [self.tipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.equalTo(self.bookImage);
        make.width.mas_equalTo(YNUM(22));
        make.height.mas_equalTo(YNUM(12));
    }];
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, YNUM(22), YNUM(12)) byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(YNUM(4), YNUM(4))];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.tipLabel.bounds;
    maskLayer.path = maskPath.CGPath;
    self.tipLabel.layer.mask = maskLayer;
    
//    self.indexLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#E0B372") andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.contentView];
//    [self.indexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.bookImage).offset(YNUM(5));
//        make.left.equalTo(self.bookImage.mas_right).offset(YNUM(6));
//    }];
    
    self.bookName = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#010101") andBgColor:nil andFont:YFont(14) andLines:2 andRadius:0 andAddSubView:self.contentView];
    [self.bookName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bookImage.mas_right).offset(YNUM(6));
        make.top.equalTo(self.bookImage).offset(YNUM(5));
        make.width.mas_equalTo(YNUM(90));
    }];
    
    self.authorLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#909090") andBgColor:nil andFont:YFont(12) andLines:1 andRadius:0 andAddSubView:self.contentView];
    [self.authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.equalTo(self.bookName);
        make.bottom.equalTo(self.bookImage.mas_bottom).offset(-YNUM(5));
    }];
}

- (void)sendBookBDsModel:(BookBDsModel *)model andIndex:(NSInteger)index {
    [self.bookImage sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:YImage(@"placeholderImage")];
//    self.indexLabel.text = [NSString stringWithFormat:@"%ld",index+1];
//    if (index < 3) {
//        self.indexLabel.textColor = COLOR(@"E0B372");
//    }else {
//        self.indexLabel.textColor = COLOR(@"#010101");
//    }
    self.bookName.text = model.name;
    self.authorLabel.text = model.author;
    [AYTool setBookStatusWithStatus:model.status andLabel:self.tipLabel];
}
@end
